package com.ymttest.database.sqlwapper.godfreight;

import com.ymt.core.tool.FormatUtil;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.freight_template_detail;
import com.ymttest.database.model.godfreight.CollectiongoodsAddress;
import com.ymttest.database.model.godfreight.CollectiongoodsAddressExample;
import com.ymttest.database.model.godfreight.DeliveryPatternConfig;
import com.ymttest.database.model.godfreight.DeliveryPatternConfigExample;
import com.ymttest.utils.EnvSetup;

import java.util.HashMap;
import java.util.List;

/************************************************************************************
 * 神器自提相关
 * @File name :CollectionGoodsWapper.java
 * @Author : zhouyi
 * @Date : 2020年4月16日
 * @Copyright : 洋码头
 ************************************************************************************/
public class CollectionGoodsWapper {
	SqlManager manager;

    public CollectionGoodsWapper() {
        manager = new SqlManager("mysqlgodfreight" + EnvSetup.getEnv());
    }

    /**
     * 查询自提地址
     * @param addressid 地址id
     * @param sellerid 商家id
     * @return
     */
    public List<CollectiongoodsAddress> selectCollectiongoodsAddress(Integer addressid,Integer sellerid) {
    	CollectiongoodsAddressExample example=new CollectiongoodsAddressExample();
    	com.ymttest.database.model.godfreight.CollectiongoodsAddressExample.Criteria c = example.createCriteria();
    	if(addressid!=null&&addressid>0) {
    		c.andAddressIdEqualTo(addressid);
    	}
    	if(sellerid!=null&&sellerid>0) {
    		c.andSellerIdEqualTo(sellerid);
    	}
    	example.setOrderByClause(" UpdateTime desc ");
//    	c.andDeletedEqualTo(false);
        List<CollectiongoodsAddress> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.godfreight.CollectiongoodsAddressMapper.selectByExample",
                        example);
        manager.commit();
        return result;
    }
    
    /**
     * 查询自提设置
     * @param sellerid
     * @return
     */
    public List<DeliveryPatternConfig> selectDeliveryPatternConfig(Integer sellerid) {
    	DeliveryPatternConfigExample example=new DeliveryPatternConfigExample();
    	 com.ymttest.database.model.godfreight.DeliveryPatternConfigExample.Criteria c = example.createCriteria();
    	if(sellerid!=null&&sellerid>0) {
    		c.andSellerIdEqualTo(sellerid);
    	}
        List<DeliveryPatternConfig> result = manager
                .getSelectResults(
                        "com.ymttest.database.mapping.godfreight.DeliveryPatternConfigMapper.selectByExample",
                        example);
        manager.commit();
        return result;
    }

    public static void main(String[] args) {
        CollectionGoodsWapper CollectionGoodsWapper = new CollectionGoodsWapper();
        System.out.println(FormatUtil.beanToGSONString(CollectionGoodsWapper.selectCollectiongoodsAddress(1, 10016)));
        System.out.println(FormatUtil.beanToGSONString(CollectionGoodsWapper.selectDeliveryPatternConfig(1)));
    }
}
